<?php 
session_start();
include("db_connect.php");
include("shop/functions.php");

if(isset($_SESSION['username']) && isset($_SESSION['password']) ){
	
	if($_SESSION['type'] == 1){
		header("location:admin.php");
	}
	else if($_SESSION['type'] == 2){
		header("location:cashier.php");
	}
	else if ($_SESSION['type'] == 3){
		
	}

}
else{
header("location:index.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Basciautosales store the place where you can buy trade set build your own dream cars at its your ways" />
<meta name="description" content="Basciautosales store the place where you can buy trade set build your own dream cars at its your ways" />


<title>Station Shop Theme, About Our Company</title>


<script type="text/javascript" src="js/clock.js"></script>
<?php include("include/jquery.php");

$msg= "";
$pid ="";
$q="";
if(isset($_REQUEST['command'])){

		if($_REQUEST['command']=='delete' && $_REQUEST['pid']>0){
		remove_product($_REQUEST['pid']);
		}
		else if($_REQUEST['command']=='clear'){
			unset($_SESSION['cart']);
		}
		else if($_REQUEST['command']=='update'){
			$max=count($_SESSION['cart']);
			for($i=0;$i<$max;$i++){
				$pid=$_SESSION['cart'][$i]['productid'];
				$q=intval($_REQUEST['product'.$pid]);
					
					if($q>0 && $q<=999){
						$_SESSION['cart'][$i]['qty']=$q;
						
					}
					else{
						$msg='Some proudcts not updated!, quantity must be a number between 1 and 999';
					}
					
				
				
				
				
			}
		}
	
}
	


?>




  
<script>
$(document).ready(function (){
$("#addnewauto").html(loader).load("profile/addnewauto.php");
$("#mybuyed_item").html(loader).load("profile/mybuyed_item.php");
$("#mytradein").html(loader).load("profile/traderdata_search.php");

$('#calendar').datepicker({
		inline: true
	});
	
$("#accordion_auto").accordion({heightStyle: "content", collapsible: true});
$("#accordion").accordion({heightStyle: "content", collapsible: true});

$("#addbrand").change(function () {
		model = $("#src_model").val();
		fname = $("#searchFname").val();
		lname = $("#searchLname").val();	
		brand = $(this).attr("value");
		var model2="model";
		if(brand == "select"){
			brand=="";
		}
		
		$("#add_model").empty().load("profile/selection.php?command="+model2 +"&modelid="+brand);
		//$("#itemRequest").html(loader).load("admin/itemRequest.php?brand="+brand+"&model="+model+"&fname="+fname+"&lname="+lname);
		
});
	
	
	
});/*end of document ready*/

$(function(){
	
    $("#tabs #tab").click(function() {
	var tab = $(this).attr("name");
	$.ajax({
	url:"scripts/tabseter.php?no="+tab,
	success:function(data){}
	});
	
  });
	
 $( "#tabs" ).tabs({ selected: <?php if(isset($_SESSION['tabadmin'] )){ echo $_SESSION['tabadmin']; } else{ echo $_SESSION['tabadmin'] = 0; } ?>

 });
 
});/*end of function*/
$(function() {
$("#tbldashboard").hide();
var on = true;
$("#myaccount").on("click", function (){
	if(on){
	$("#tbldashboard").slideDown().show();		
	on = false;
	}else{
	$("#tbldashboard").slideDown().hide();
	on = true;
	}
});

$("#editAccount").click(function () {
		$("#fname").removeAttr('disabled');
		$("#lname").removeAttr('disabled');
		$("#email").removeAttr('disabled');
		$("#contact").removeAttr('disabled');
		$("#uname").removeAttr('disabled');
		$("#pass").removeAttr('disabled');
		$("#save").removeAttr('disabled');
	});
$("#save").click(function () {
	var fname =	$("#fname");
	var lname =	$("#lname");
	var num = $("#contact");
	var	email = $("#email");
	var	uname = $("#uname");
	var	pass = $("#pass");
		
	if(fname.val() == "" || fname.val() == " "){
		alert("empty first name");
	}
	else if(lname.val() == "" || lname.val() == " "){
		alert("empty last name");
	}
	else if(num.val() == "" || num.val() == " "){
		alert("empty contact");
	}
	else if(isNaN(num.val())){
		alert("No. Only");
	}
	else if(email.val() == "" || email.val() == " "){
		alert("empty email");
	}
	else if(!isValidEmail( email.val() ) ){
		alert("input a valid email")
	}
	else if(uname.val() == "" || uname.val()== " "){
		alert("empty username");
	}
	else {
		checkusername(fname,lname,num,email,uname,pass) 
	}
});	



	
});/*end of function*/
/*edit user account*/
function checkusername(fname, lname,  num, email,  uname, pass){
	if(uname.val() == "" || uname.val()== " "){
		alert("empty username");
	}
	else{
		$.ajax ({
				url:"scripts/isusername_exist.php?username="+uname.val(),
					success:function(data){
						if(data == 1){
							if(confirm("This is your current username > " +uname.val()+ " < do you want to change it?")){
							
							}
							else{
							//dapat merun comfirmation ng password eh tinamad ako haha saka ko na gagawin
								update(fname, lname,  num, email,  uname, pass);
							}
						}
						else{
							update(fname, lname,  num, email,  uname, pass);
						
						}
				}
			});
	}
}

function update(fname, lname,  num, email,  uname, pass){
	$.ajax({
	url:"admin/update.php?fname="+fname.val()+"&lname="+lname.val()+"&num="+num.val()+"& email="+email.val()+"&uname="+uname.val()+"&pass="+pass.val(),
	success:function(data){
		if(data=="1"){
			alert("Successfuly updated");
			location.reload();
		}
		else{
			location.reload();
		}
	
	}
	
	});
		
	
}
/*just checking for a valid email format*/
function isValidEmail(strEmail){
var validRegExp;
validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1){
		return false;
    } 
    return true; 
}
/*end of edit account*/


/*check all data*/
checked = false;		  
function checkedAll(){
	if (checked == false){
		checked = true
	}
	else{
	checked = false
	}
	for (var i = 0; i < document.getElementById('myform').elements.length; i++){
		document.getElementById('myform').elements[i].checked = checked;
	}	
}



</script>
<script>

function redirect(){
	var command = "sessioncheck";
	$.ajax({
	url:"scripts/issessionset.php?command="+command,
	success:function(data){
		if(data == 1){
			window.location.href = "paypal/mybill.php" 
		}
		else{
			$("#msgbox").html("log in first");
			$("#msgbox").dialog({
				modal:true,
				width:350,
				height: 200,
				show:"fade",
				hide: "fade",
				buttons: {
					login: function() {
						window.location.href = "mylogin.php";
					},
					CANCEL: function() {
						$( this ).dialog( "close" );
					}
				},
			
			});
		}
		
		
	}
	});
	
}
function del(pid){
		if(confirm('Do you really mean to delete this item')){
			document.form1.pid.value=pid;
			document.form1.command.value='delete';
			document.form1.submit();
		}
	}
function clear_cart(){
		if(confirm('This will empty your shopping cart, continue?')){
			document.form1.command.value='clear';
			document.form1.submit();
		}
}
function update_cart(){
	document.form1.command.value='update';
	document.form1.submit();
}
function update_cart(){
var qtyarray = new Array();
$("#placeOrderTable tr td").find("input:text").each(function(e){
	var pid = $(this).attr('name');
	var qty = $(this).val();
	var pid2 = pid.split('product');
	//alert(qty);
	qtyarray[e+e] = qty+pid2;
	

});
	update_mycart(qtyarray);

}


function update_mycart(qtycheck){
	$.ajax({
		url:"scripts/qtycheck.php?qtyid="+qtycheck,
		success:function(data){
		//alert(data);
			if(data=='true'){
				alert("Please check our stock qty it seems you exceed to our limit stock.");
				return false;
			}
			else{
			document.form1.command.value='update';
			document.form1.submit();
			}
				
		}		
	
	});
	
}


function deleteallcart(){

	var command = "deleteall";
	if(confirm("Do you want to clear your cart?")){
	$.ajax({
				url:"shop/cart.php?command="+command,
				success:function(data){
				
				location.reload();
				
				}		
			})
	}
}


function delMyitem(value){
if(confirm("Do you want to delete this?")){
$.ajax({
	url:"profile/modifyData.php?value="+value,
	success:function(data){
		$("#mybuyed_item").html(loader).load("profile/mybuyed_item.php");
	}

});


}

}

</script>
</head>

<body>
<div id="msgbox"></div>
<div id="templatemo_wrapper">
	<!--header-->
		<?php include("include/header.php");?>
	<!--header-->
    
    <div id="templatemo_main">
   		<!--sidebar-->
		<div id="sidebar" class="float_l">
			<!--top-->
			<div class="sidebar_box">
				<h3>Account</h3>   
                <div class="content"> 
				<a href="#myaccount" id="myaccount" style="font-size:17px; color:red;" >Update Account </a>
				<div style="color:white;">_</div>
							<?php
								$sql = "Select * from tbl_account where id=".$_SESSION['id']." ";
								$result = mysql_query($sql);
								while($row = mysql_fetch_array($result)){
									$fname = $row['fname'];
									$lname = $row['lname'];
									$email = $row['email'];
									$contact = $row['contacts'];
									$password = base64_decode($row['password']);
									$username = $row['username'];
								}
							?>
							<table id="tbldashboard" style="background-color:black">
								<tr>
									<td>First Name:</td>
									<td><input type="text" id="fname" value="<?php echo $fname?>" disabled/> </td>
								</tr>
								<tr>
									<td>Last Name:</td>
									<td><input type="text" id="lname" value="<?php echo $lname?>" disabled/> </td>
								</tr>		
								<tr>
									<td>Contact no:</td>
									<td><input type="text" id="contact" value="<?php echo $contact;?>" disabled/></td>
								</tr>
								<tr>
									<td>Email:</td>
									<td><input type="text" id="email" value="<?php echo $email;?>" disabled/></td>
								</tr>
								<tr>
									<td>Username:</td>
									<td><input type="text" id="uname" value="<?php echo $username;?>" disabled/></td>
								</tr>
								<tr>
									<td>Password:</td>
									<td><input type="password" id="pass" value="<?php echo $password;?>" disabled/></td>
								</tr>
								<tr>
									<td colspan="2">
										<button id="editAccount" >Edit</button>
										<button id="save" disabled>Save</button>
									</td>
								</tr>
							</table>
                	
                </div>
			</div>
			<div class="sidebar_box">
			<h3>Local Time</h3>   
                <div class="content"> 
                	<div id="clockbox" style="font-size:20px; color:#F71313; margin:auto; position:relaative; z-index:300;">
						<p align="center" id="clockboxp" style="margin-bottom:5px;"></p>
					</div>
					
					<div id="calendar" style="margin-left:-10px;"></div>
					<p style="color:white">_</p>
					
			    </div>
			</div>
			
        		
			<!--sidebox best end seller-->
		</div><!--siderbar-->
		
		
        <div id="content" class="float_r" style="background-color:white; padding:0px; width:715px;">
			<div id="tabs">
				
				<ul>
					<li><a href="#tabs1" id="tab" name="0" >My Item</a></li>
					<li><a href="#tabs2" id="tab" name="1" >My Buyed Item</a></li>
					<li><a href="#tabs3" id="tab" name="2" >My Cart</a></li>
					<li><a href="#tabs4" id="tab" name="3" >My Trade</a></li>
					<!--li><a href="#tabs4" id="tab" name="3" >My</a></li-->
				
					
				</ul>
				
				<div id="tabs1">
					<div id="accordion">
					<h4 style="color:white">My item</h4>
					<div style="overflow:auto">
						
						<?php include("profile/myItem.php");?>
					</div>
					<h4 style="color:white">My Auto</h4>
					<div style="width:627px; overflow:auto">
						<div  id="addnewauto" style="width:627px;" align="center"></div>
					</div>
					</div>
				</div>
				<!--end of tab1-->
				<div id="tabs4">
					<div id="mytradein" style="width:100%; overflow:auto">
					</div>
				</div>
				
				<div id="tabs2">
					<!--Myitem-->
					
					<div id="accordion_auto">
							<h4 style="color:white">Buyed Items</h4>
							<div id="mybuyed_item" style="overflow:auto;">
															
							</div>
							

					</div>
					
					
					
					
					<!--cart-->
				</div>
				<!--end of tab2-->
				<div id="tabs3">
					<?php include("profile/mycart.php");?>
				</div>
				<!--end of tab3-->
				
				<!--end of tab4-->
				<div id="tabs5">
					
				</div>
				<!--end of tab5-->
				
				
			</div><!--end of tab-->	
        </div> 
       
		<div class="cleaner"></div>
    </div> <!-- END of templatemo_main -->
    
     <!--footer-->
	<?php //include("include/footer.php");?>
    
</div> <!-- END of templatemo_wrapper -->

</body>
</html>